package cc.lj.internal.payment.domain.settlement.service.impl;

import cc.lj.internal.payment.domain.settlement.repository.ICouponsSubsidyDetailRepository;
import cc.lj.internal.payment.domain.settlement.repository.ICouponsSubsidyRepository;
import cc.lj.internal.payment.domain.settlement.service.ICouponsSubsidyDetailDomainService;
import cc.lj.internal.payment.domain.settlement.service.ICouponsSubsidyDomainService;
import cc.lj.internal.payment.domain.settlement.vo.CouponsSubsidyDO;
import cc.lj.internal.payment.domain.settlement.vo.CouponsSubsidyDetailDO;
import cc.lj.internal.payment.domain.settlement.vo.convert.CouponsSubsidyDetailPOConvertDO;
import cc.lj.internal.payment.domain.settlement.vo.convert.CouponsSubsidyPOConvertDO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 电子券补贴明细表 domain service 实现类
 * @author liangxifeng
 * @date 2022/10/23 17:13
 */
@Service("couponsSubsidyDetailDomainServiceImpl")
@Slf4j
public class CouponsSubsidyDetailDomainServiceImpl implements ICouponsSubsidyDetailDomainService {
    @Resource(name = "couponsSubsidyDetailRepository")
    private ICouponsSubsidyDetailRepository repository;


    @Override
    public Integer insert(CouponsSubsidyDetailDO subsidyDO) {
        return repository.insert(CouponsSubsidyDetailPOConvertDO.INSTANCE.convert(subsidyDO));
    }

    @Override
    public CouponsSubsidyDetailDO getById(Integer id) {
        return CouponsSubsidyDetailPOConvertDO.INSTANCE.convert( repository.getById(id) );
    }


    @Override
    public List<CouponsSubsidyDetailDO> getList(CouponsSubsidyDetailDO subsidyDO) {
        return repository.getList(CouponsSubsidyDetailPOConvertDO.INSTANCE.convert(subsidyDO))
                .stream()
                .map( x-> CouponsSubsidyDetailPOConvertDO.INSTANCE.convert(x))
                .collect(Collectors.toList());
    }

    @Override
    public BigDecimal getMartSharePriceSum(CouponsSubsidyDetailDO detailDO) {
        return repository.getMartSharePriceSum(CouponsSubsidyDetailPOConvertDO.INSTANCE.convert(detailDO) );
    }
}
